Skip to content

C API: Add JNI bridge between Java proxy classes and WebKit/WPE GObjects#250

Merged
alexgcastro merged 1 commit intomainfrom
alex/capi-add-jni-bridge
Apr 20, 2026
Merged

C API: Add JNI bridge between Java proxy classes and WebKit/WPE GObjects#250
alexgcastro merged 1 commit intomainfrom
alex/capi-add-jni-bridge

Conversation

@alexgcastro
Copy link
Copy Markdown
Collaborator

Add Java proxy wrappers plus JNI mappings for WPEDisplay, WPEToplevel, WPEView, WebKitWebContext, WebKitNetworkSession, WebKitSettings, WebKitCookieManager, WebKitWebsiteDataManager, and WebKitWebView.

Each bridged class uses a JNI::TypedClass singleton to register native methods and cache Java method IDs at library load time, avoiding repeated JNI lookups in GLib and async callbacks. JNIMappings initialises all singletons during JNI_OnLoad.

WebKitWebView and WebKitWebContext use per-object bridge structs that own the native GObject reference, keep a Java GlobalRef back-reference where needed, and track GLib signal handlers for orderly disconnection on destruction. Async operations such as cookie-manager queries, website-data clears, and evaluateJavascript() keep callback holders alive with heap-allocated GlobalRef objects released when the callback runs.

WPEToplevelAndroid updates its SurfaceControl tree as native windows are attached and detached, and treats repeated set_window() calls for the same ANativeWindow as a size resync instead of rebuilding the layer tree.

Native callbacks may arrive off the main thread; Java-side listener and async result delivery is reposted to the main looper before application-facing callback code runs.

Comment thread wpeview/src/main/cpp/capi/WebKitCookieManager.cpp Outdated
Comment thread wpeview/src/main/cpp/capi/WebKitCookieManager.cpp
Comment thread wpeview/src/main/cpp/capi/WebKitWebContext.cpp Outdated
Comment thread wpeview/src/main/cpp/capi/WebKitWebContext.cpp Outdated
Comment thread wpeview/src/main/cpp/capi/WebKitWebContext.cpp Outdated
Comment thread wpeview/src/main/cpp/capi/WebKitWebView.cpp Outdated
Comment thread wpeview/src/main/cpp/capi/WebKitWebView.cpp
Comment thread wpeview/src/main/cpp/capi/WebKitWebView.cpp
Comment thread wpeview/src/main/cpp/capi/WPEView.cpp Outdated
Comment thread wpeview/src/main/cpp/capi/WPEView.cpp Outdated
@alexgcastro
Copy link
Copy Markdown
Collaborator Author

@spenap thanks for the review!

Add Java proxy wrappers plus JNI mappings for WPEDisplay, WPEToplevel,
WPEView, WebKitWebContext, WebKitNetworkSession, WebKitSettings,
WebKitCookieManager, WebKitWebsiteDataManager, and WebKitWebView.

Each bridged class uses a JNI::TypedClass<T> singleton to register native
methods and cache Java method IDs at library load time, avoiding repeated
JNI lookups in GLib and async callbacks. JNIMappings initialises all
singletons during JNI_OnLoad.

WebKitWebView and WebKitWebContext use per-object bridge structs that own
the native GObject reference, keep a Java GlobalRef back-reference where
needed, and track GLib signal handlers for orderly disconnection on
destruction. Async operations such as cookie-manager queries, website-data
clears, and evaluateJavascript() keep callback holders alive with
heap-allocated GlobalRef<T> objects released when the callback runs.

WPEToplevelAndroid updates its SurfaceControl tree as native windows are
attached and detached, and treats repeated set_window() calls for the same
ANativeWindow as a size resync instead of rebuilding the layer tree.

Native callbacks may arrive off the main thread; Java-side listener and
async result delivery is reposted to the main looper before
application-facing callback code runs.
@alexgcastro alexgcastro force-pushed the alex/capi-add-jni-bridge branch from 5fd90f4 to a70f4cb Compare April 17, 2026 11:17
Copy link
Copy Markdown
Collaborator

@spenap spenap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@alexgcastro alexgcastro merged commit 3af4d1c into main Apr 20, 2026
6 checks passed
@alexgcastro alexgcastro deleted the alex/capi-add-jni-bridge branch April 20, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants